from random import randint

import pygame
from pygame.locals import *
from sys import exit
import  math

pygame.init()
screen = pygame.display.set_mode((640, 640), 0, 32)

clock = pygame.time.Clock()

class ArrayLine():

    def __init__(self, startP, endP,color, sc, isdash=False):

        self.StartPoint=startP
        self.EndPoint=endP
        self.Color=color
        self.IsDashLine=isdash
        self.Scree=sc



    def DrawLine(self):
        if not self.IsDashLine:

           pygame.draw.line(self.Screen,self.Color,self.StartPoint,self.EndPoint,width=1)

    def Distance(self):
        return math.sqrt((self.StartPoint[0]-self.EndPoint[0])**2+(self.StartPoint[1]-self.EndPoint[1])**2)




    def DrawArray(self):
          Length=self.Distance()/10

          if (self.StartPoint[0]-self.EndPoint[0])==0 & self.EndPoint[1]>self.StartPoint[1] :
              Angle=math.pi
          elif (self.StartPoint[0]-self.EndPoint[0])==0 & self.EndPoint[1]<self.StartPoint[1]:
              Angle=-math.pi
          else:
              Angle=math.atan((self.StartPoint[1]-self.EndPoint[1])/(self.StartPoint[0]-self.EndPoint[0]))

          Point1=(self.EndPoint[0]+Length*math.cos(Angle), self.EndPoint[1]+Length*math.sin(Angle))

          Edge=Length/math.cos(math.pi/3)





class MoveCylcle():

    def __init__(self, x, y,vx0,vy0,sr,isGOpen=True):
        self.x = x
        self.y=y
        self.Cycle=(x,y)
        self.IsGOpen=isGOpen

        self.CollisionLostRation=0.6
        self.screen=sr
        self.g=9.8

        self.Radis=10
        self.Vx0=vx0
        self.Vy0=vy0
        self.Color=(randint(0,255),randint(0,255),randint(0,255))


    def move(self, t):

        if self.x > 640 - 10:

            self.x = 640-10
            self.Vx0=-self.Vx0*self.CollisionLostRation
        elif self.x < 0:

            self.x = 0.
            self.Vx0 = -self.Vx0*self.CollisionLostRation

        if self.y > 640 - 10:

            self.y = 640 - 10
            self.Vy0= -self.Vy0*self.CollisionLostRation
            self.g=0

        elif self.y < 0:

            self.y = 0
            self.Vy0 = -self.Vy0*self.CollisionLostRation
        else:self.g=9.8

        self.x += self.Vx0 * t
        self.y += self.Vy0 * t + 0.5 * self.g * t * t
        self.Vy0 = self.Vy0 + self.g * t

        self.Draw()



    def Draw(self):
        pygame.draw.circle(self.screen, self.Color, (self.x, self.y), self.Radis)



GoodList=[]


for i in range(1000):

    GoodList.append(MoveCylcle(320, 320,randint(0,40)*math.cos(2*math.pi*i/1000),randint(0,40)*math.sin(2*math.pi*i/1000),screen, True))




TimeTotal=0.0

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()
    screen.fill((255,255,255))
    time_passed = clock.tick(30)
    TimeTotal += time_passed / 1000.0
    for ii in GoodList:
        ii.move(time_passed / 1000.0)






    pygame.display.set_caption("Time passed - %.3f" % TimeTotal)












    pygame.display.update()



